// package com.learn.mydruid.conf;
//
// import com.alibaba.druid.pool.DruidDataSource;
// import java.sql.SQLException;
// import java.util.Properties;
// import javax.sql.DataSource;
// import org.springframework.beans.factory.annotation.Value;
// import org.springframework.boot.context.properties.ConfigurationProperties;
// import org.springframework.context.annotation.Bean;
// import org.springframework.context.annotation.Configuration;
// import org.springframework.context.annotation.Primary;
// import org.springframework.context.annotation.PropertySource;
// import org.springframework.stereotype.Component;
//
// @Component
// @Configuration
// @ConfigurationProperties(prefix = "spring.datasource")
// @PropertySource("classpath:application.yml")
// public class DataSourceProperties {
//     @Value("${driver-class-name}")
//     private String driverClassName;
//     @Value("${url}")
//     private String url;
//     @Value("${username}")
//     private String username;
//     @Value("${password}")
//     private String password;
//
//     @Value("${druid.initialSize}")
//     private int initialSize;
//     @Value("${druid.minIdle}")
//     private int minIdle;
//     @Value("${druid.maxActive}")
//     private int maxActive;
//     @Value("${maxWait}")
//     private int maxWait;
//     @Value("${timeBetweenEvictionRunsMillis}")
//     private int timeBetweenEvictionRunsMillis;
//     @Value("${minEvictableIdleTimeMillis}")
//     private int minEvictableIdleTimeMillis;
//     @Value("${validationQuery}")
//     private String validationQuery;
//     @Value("${testWhileIdle}")
//     private boolean testWhileIdle;
//     @Value("${testOnBorrow}")
//     private boolean    testOnBorrow;
//     @Value("${testOnReturn}")
//     private boolean    testOnReturn;
//     @Value("${poolPreparedStatements}")
//     private boolean    poolPreparedStatements;
//     @Value("${maxPoolPreparedStatementPerConnectionSize}")
//     private int        maxPoolPreparedStatementPerConnectionSize;
//     @Value("${filters}")
//     private String     filters;
//     @Value("${connectionProperties}")
//     private Properties connectionProperties;
//
//
//     @Bean //声明为Bean实例对象
//     @Primary //在同样的DataSource中优先使用被标注的DataSource
//     public DataSource dataSource() {
//
//         DruidDataSource dataSource = new DruidDataSource();
//         dataSource.setUrl(url);
//         dataSource.setUsername(username);
//         dataSource.setPassword(password);
//         dataSource.setDriverClassName(driverClassName);
//
//         //Configuration
//         dataSource.setInitialSize(initialSize);
//         dataSource.setMinIdle(minIdle);
//         dataSource.setMaxActive(maxActive);
//         dataSource.setMaxWait(maxWait);
//         dataSource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
//         dataSource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
//         dataSource.setValidationQuery(validationQuery);
//         dataSource.setTestWhileIdle(testWhileIdle);
//         dataSource.setTestOnBorrow(testOnBorrow);
//         dataSource.setTestOnReturn(testOnReturn);
//         dataSource.setPoolPreparedStatements(poolPreparedStatements);
//         dataSource.setMaxPoolPreparedStatementPerConnectionSize(maxPoolPreparedStatementPerConnectionSize);
//         try {
//             dataSource.setFilters(filters);
//         } catch (SQLException e) {
//             e.printStackTrace();
//         }
//         dataSource.setConnectProperties(connectionProperties);
//         return dataSource;
//     }
// }